<script setup>
import { ref, computed, onMounted, onUnmounted, onUpdated, nextTick, watch, triggerRef } from 'vue'
import MarkdownRenderer from './components/MarkdownRenderer.vue'
import UploadKnowledgeBase from './components/UploadKnowledgeBase.vue'
import KnowledgeCarousel from './components/KnowledgeCarousel.vue'

const messages = computed(() => {
  const currentChat = chatHistory.value.find((chat) => chat.id === currentChatId.value)
  return currentChat ? currentChat.messages : []
})

const inputMessage = ref('')
const isLoading = ref(false)
const messagesEndRef = ref(null)
const workflowNodes = ref([])
const expandedNodes = ref([])
const autoScrollEnabled = ref(true)
const workflowContainer = ref(null)
// 打字机效果配置
const typewriterConfig = ref({
  enabled: true,
  baseSpeed: 30, // 基础速度（毫秒/字符）
  punctuationDelay: 100, // 标点符号延迟
  lineBreakDelay: 50, // 换行延迟
  spaceDelay: 10, // 空格延迟
})
const sseConnection = ref(null)
const showUploadModal = ref(false)
const sseConnectionStatus = ref('disconnected')
const connectionMonitorInterval = ref(null)
const isReconnecting = ref(false)
const isInspectionRunning = ref(false)
const expandedOutputs = ref([])
const chatHistory = ref([
  {
    id: 1,
    title: '当前对话',
    preview: '你好！我是智能运维助手，专注于系统监控、故障诊断和性能优化...',
    messages: [
      {
        id: 1,
        type: 'assistant',
        content:
          '你好！我是智能运维助手，专注于系统监控、故障诊断和性能优化。我可以帮助你进行系统巡检、分析日志、优化性能、解决问题等。有什么需要我协助的吗？',
        timestamp: new Date(),
        isStreaming: false,
      },
    ],
    isActive: true,
  },
  
])

// 知识搜索数据 - 黑客命令行风格
const knowledgeItems = ref([])
const currentChatId = ref(1)

const scrollToBottom = (force = false) => {
  nextTick(() => {
    if (messagesEndRef.value) {
      const container = messagesEndRef.value.parentElement
      if (container) {
        // 如果强制滚动或用户接近底部，则执行滚动
        const isNearBottom =
          container.scrollHeight - container.scrollTop - container.clientHeight < 100
        
        if (force || isNearBottom) {
          // 使用 scrollTop 方式确保滚动到底部
          container.scrollTop = container.scrollHeight
          // 备用方案：使用 scrollIntoView
          messagesEndRef.value.scrollIntoView({ behavior: 'smooth', block: 'end' })
        }
      }
    }
  })
}

const sendMessage = () => {
  if (!inputMessage.value.trim() || isLoading.value) return

  const currentChat = chatHistory.value.find((chat) => chat.id === currentChatId.value)
  if (!currentChat) return

  const userMessageId = Date.now()
  const userMessage = {
    id: userMessageId,
    type: 'user',
    content: inputMessage.value,
    timestamp: new Date(),
    isStreaming: false, // 用户消息不需要流式输出
  }

  currentChat.messages.push(userMessage)
  const userInput = inputMessage.value
  inputMessage.value = ''
  isLoading.value = true

  // Update preview
  currentChat.preview = userInput.length > 50 ? userInput.substring(0, 50) + '...' : userInput

  // 强制滚动到底部
  scrollToBottom(true)

  // 创建AI消息占位符 - 确保ID不同
  const aiMessageId = Date.now() + 1
  const aiMessage = {
    id: aiMessageId,
    type: 'assistant',
    content: '',
    status: '[状态] 正在连接...',
    timestamp: new Date(),
    isStreaming: true,
  }
  currentChat.messages.push(aiMessage)
  let fullResponse = ''
  
  // 添加 AI 消息后立即滚动到底部
  nextTick(() => {
    scrollToBottom(true)
  })
  
  console.log('创建了消息:')
  console.log('用户消息 ID:', userMessageId, '类型: user')
  console.log('AI 消息 ID:', aiMessageId, '类型: assistant')
  console.log('当前消息列表:', currentChat.messages.map(m => ({ id: m.id, type: m.type, contentLength: m.content.length })))

  // 使用EventSource处理SSE流
  const streamUrl = `http://localhost:8081/chat/stream?question=${encodeURIComponent(userInput)}`
  console.log('开始流式请求:', streamUrl)
  
  const eventSource = new EventSource(streamUrl)

  eventSource.onmessage = (event) => {
    console.log('收到 SSE 消息:', event.data)
    
    try {
      let rawData = event.data.trim()
      
      // 处理结束标志
      if (rawData === 'event:end' || rawData === '[DONE]' || rawData === 'data: [DONE]') {
        console.log('收到结束标志')
        
        const messageIndex = currentChat.messages.findIndex(msg => msg.id === aiMessageId && msg.type === 'assistant')
        if (messageIndex !== -1) {
          currentChat.messages[messageIndex].isStreaming = false
          currentChat.messages[messageIndex].status = '[状态] 处理完成'
          
          console.log('AI 消息处理完成，索引:', messageIndex)
        } else {
          console.error('未找到 AI 消息进行完成标记，aiMessageId:', aiMessageId)
        }
        
        isLoading.value = false
        eventSource.close()
        
        nextTick(() => {
          scrollToBottom(true)
        })
        return
      }

      // 移除 data: 前缀（如果存在）
      if (rawData.startsWith('data: ')) {
        rawData = rawData.substring(6).trim()
      }

      // 如果是空数据或心跳包，跳过
      if (!rawData || rawData === ':' || rawData === 'data:') {
        console.log('跳过空数据或心跳包')
        return
      }

      console.log('处理数据:', rawData)

      // 尝试解析 JSON
      let data
      try {
        data = JSON.parse(rawData)
        console.log('解析的 JSON 数据:', data)
      } catch (parseError) {
        console.log('非 JSON 数据，直接作为文本处理:', rawData)
        // 如果不是 JSON，直接作为文本处理
        if (rawData.trim()) {
          fullResponse += rawData
          
          // 强制触发 Vue 响应式更新
          const messageIndex = currentChat.messages.findIndex(msg => msg.id === aiMessageId && msg.type === 'assistant')
          if (messageIndex !== -1) {
            currentChat.messages[messageIndex].content = fullResponse
            currentChat.messages[messageIndex].isStreaming = true
            
            // 强制触发响应式更新
            triggerRef(chatHistory)
            
            console.log('更新了 AI 消息，索引:', messageIndex, '类型:', currentChat.messages[messageIndex].type)
          } else {
            console.error('未找到 AI 消息，aiMessageId:', aiMessageId)
          }
          
          console.log('更新内容长度:', fullResponse.length)
          console.log('消息内容预览:', fullResponse.substring(0, 50) + '...')
          
          // 使用 nextTick 确保 DOM 更新后再滚动，AI回复时强制滚动
          nextTick(() => {
            scrollToBottom(true)
          })
        }
        return
      }

      // 处理节点状态
      if (data.node) {
        console.log('处理节点状态:', data.node)
        
        const messageIndex = currentChat.messages.findIndex(msg => msg.id === aiMessageId && msg.type === 'assistant')
        if (messageIndex !== -1) {
          if (data.node === '__START__') {
            currentChat.messages[messageIndex].status = '[状态] 开始处理...'
          } else if (data.node === '__END__') {
            currentChat.messages[messageIndex].status = '[状态] 处理完成'
            currentChat.messages[messageIndex].isStreaming = false
            isLoading.value = false
            eventSource.close()
          } else {
            currentChat.messages[messageIndex].status = `[状态] 正在执行: ${data.node}`
          }
          
          console.log('更新了 AI 消息状态，索引:', messageIndex, '状态:', currentChat.messages[messageIndex].status)
        } else {
          console.error('未找到 AI 消息进行状态更新，aiMessageId:', aiMessageId)
        }
        
        nextTick(() => {
          scrollToBottom()
        })
        return
      }

      // 处理流式文本内容 - 支持多种字段名
      let textChunk = ''
      if (data.content) {
        textChunk = data.content
      } else if (data.text) {
        textChunk = data.text
      } else if (data.message) {
        textChunk = data.message
      } else if (data.llmNode) {
        textChunk = data.llmNode
      } else if (data.chunk) {
        textChunk = data.chunk
      } else if (data.delta) {
        textChunk = data.delta
      } else if (typeof data === 'string') {
        textChunk = data
      }

      // 添加文本块到响应中
      if (textChunk) {
        console.log('添加文本块:', textChunk)
        fullResponse += textChunk
        
        // 强制触发 Vue 响应式更新
        const messageIndex = currentChat.messages.findIndex(msg => msg.id === aiMessageId && msg.type === 'assistant')
        if (messageIndex !== -1) {
          currentChat.messages[messageIndex].content = fullResponse
          currentChat.messages[messageIndex].isStreaming = true
          
          // 强制触发响应式更新
          triggerRef(chatHistory)
          
          console.log('更新了 AI 消息，索引:', messageIndex, '类型:', currentChat.messages[messageIndex].type)
        } else {
          console.error('未找到 AI 消息，aiMessageId:', aiMessageId)
        }
        
        console.log('当前完整响应长度:', fullResponse.length)
        console.log('消息内容预览:', fullResponse.substring(0, 50) + '...')
        
        // 使用 nextTick 确保 DOM 更新后再滚动，AI回复时强制滚动
        nextTick(() => {
          scrollToBottom(true)
        })
      } else {
        console.log('未找到可处理的文本内容，数据结构:', Object.keys(data))
      }

    } catch (e) {
      console.error('处理 SSE 消息时出错:', e, '原始数据:', event.data)
    }
  }

  eventSource.onerror = (error) => {
    console.error('EventSource 错误:', error)
    eventSource.close()
    aiMessage.isStreaming = false

    if (fullResponse.trim()) {
      aiMessage.content = fullResponse
      aiMessage.status = '[状态] 部分完成（连接中断）'
    } else {
      const errorMessage = `❌ **请求失败**\n\n无法连接到后端服务，请检查:\n1. 后端服务是否运行在8081端口\n2. 网络连接是否正常\n3. 后端是否支持 CORS`
      aiMessage.content = errorMessage
      aiMessage.status = '[状态] 连接错误'
    }

    isLoading.value = false
    scrollToBottom()
  }

  eventSource.onopen = () => {
    console.log('EventSource 连接已建立')
    aiMessage.status = '[状态] 已连接，等待数据...'
    scrollToBottom()
  }

  // 监听自定义结束事件
  eventSource.addEventListener('end', () => {
    console.log('收到结束事件')
    aiMessage.content = fullResponse
    aiMessage.status = '[状态] 已完成'
    aiMessage.isStreaming = false
    eventSource.close()
    isLoading.value = false
    scrollToBottom()
  })

  // 设置超时处理（60秒）
  const timeoutId = setTimeout(() => {
    if (eventSource.readyState !== EventSource.CLOSED) {
      console.log('请求超时，关闭连接')
      eventSource.close()
      aiMessage.isStreaming = false

      if (fullResponse.trim()) {
        aiMessage.content = fullResponse
        aiMessage.status = '[状态] 部分完成（超时）'
      } else {
        const timeoutMessage = `❌ **请求超时**\n\n请求超时（60秒），请检查:\n1. 后端服务状态\n2. 网络连接稳定性\n3. 请求是否过于复杂`
        aiMessage.content = timeoutMessage
        aiMessage.status = '[状态] 请求超时'
      }

      isLoading.value = false
      scrollToBottom()
    }
  }, 600000)

  // 在连接关闭时清除超时
  const originalClose = eventSource.close.bind(eventSource)
  eventSource.close = () => {
    clearTimeout(timeoutId)
    originalClose()
  }
}
//流式报告
const sendReport= () => {

  const currentChat = chatHistory.value.find((chat) => chat.id === currentChatId.value)

  const userMessageId = Date.now()
  const userMessage = {
    id: userMessageId,
    type: 'user',
    content: inputMessage.value,
    timestamp: new Date(),
    isStreaming: false, // 用户消息不需要流式输出
  }

  const userInput = inputMessage.value
  inputMessage.value = ''
  isLoading.value = true

  // Update preview
  currentChat.preview = userInput.length > 50 ? userInput.substring(0, 50) + '...' : userInput

  // Update preview
  scrollToBottom(true)

  // 创建AI消息占位符 - 确保ID不同
  const aiMessageId = Date.now() + 1
  const aiMessage = {
    id: aiMessageId,
    type: 'assistant',
    content: '',
    status: '[状态] 正在连接...',
    timestamp: new Date(),
    isStreaming: true,
  }
  currentChat.messages.push(aiMessage)
  let fullResponse = ''

  // 添加 AI 消息后立即滚动到底部
  nextTick(() => {
    scrollToBottom(true)
  })

  // 使用EventSource处理SSE流
  const streamUrl = `http://localhost:8081/stream`
  console.log('开始流式请求:', streamUrl)
  
  const eventSource = new EventSource(streamUrl)

  eventSource.onmessage = (event) => {
    console.log('收到 SSE 消息:', event.data)
    
    try {
      let rawData = event.data.trim()
      
      // 处理结束标志
      if (rawData === 'event:end' || rawData === '[DONE]' || rawData === 'data: [DONE]') {
        console.log('收到结束标志')
        
        const messageIndex = currentChat.messages.findIndex(msg => msg.id === aiMessageId && msg.type === 'assistant')
        if (messageIndex !== -1) {
          currentChat.messages[messageIndex].isStreaming = false
          currentChat.messages[messageIndex].status = '[状态] 处理完成'
          
          console.log('AI 消息处理完成，索引:', messageIndex)
        } else {
          console.error('未找到 AI 消息进行完成标记，aiMessageId:', aiMessageId)
        }
        
        isLoading.value = false
        eventSource.close()
        
        nextTick(() => {
          scrollToBottom(true)
        })
        return
      }

      

      // 尝试解析 JSON
      let data
      try {
        data = JSON.parse(rawData)
        console.log('解析的 JSON 数据:', data)
      } catch (parseError) {
        console.log('非 JSON 数据，直接作为文本处理:', rawData)
        // 如果不是 JSON，直接作为文本处理
        if (rawData.trim()) {
          fullResponse += rawData
          
          // 强制触发 Vue 响应式更新
          const messageIndex = currentChat.messages.findIndex(msg => msg.id === aiMessageId && msg.type === 'assistant')
          if (messageIndex !== -1) {
            currentChat.messages[messageIndex].content = fullResponse
            currentChat.messages[messageIndex].isStreaming = true
            
            // 强制触发响应式更新
            triggerRef(chatHistory)
            
            console.log('更新了 AI 消息，索引:', messageIndex, '类型:', currentChat.messages[messageIndex].type)
          } else {
            console.error('未找到 AI 消息，aiMessageId:', aiMessageId)
          }
          
          console.log('更新内容长度:', fullResponse.length)
          console.log('消息内容预览:', fullResponse.substring(0, 50) + '...')
          
          // 使用 nextTick 确保 DOM 更新后再滚动，AI回复时强制滚动
          nextTick(() => {
            scrollToBottom(true)
          })
        }
        return
      }

      // 处理节点状态
      if (data.node) {
        console.log('处理节点状态:', data.node)
        
        const messageIndex = currentChat.messages.findIndex(msg => msg.id === aiMessageId && msg.type === 'assistant')
        if (messageIndex !== -1) {
          if (data.node === '__START__') {
            currentChat.messages[messageIndex].status = '[状态] 开始处理...'
          } else if (data.node === '__END__') {
            currentChat.messages[messageIndex].status = '[状态] 处理完成'
            currentChat.messages[messageIndex].isStreaming = false
            isLoading.value = false
            eventSource.close()
          } else {
            currentChat.messages[messageIndex].status = `[状态] 正在执行: ${data.node}`
          }
          
          console.log('更新了 AI 消息状态，索引:', messageIndex, '状态:', currentChat.messages[messageIndex].status)
        } else {
          console.error('未找到 AI 消息进行状态更新，aiMessageId:', aiMessageId)
        }
        
        nextTick(() => {
          scrollToBottom()
        })
        return
      }

      // 处理流式文本内容 - 支持多种字段名
      let textChunk = ''
      if (data.content) {
        textChunk = data.content
      } else if (data.text) {
        textChunk = data.text
      } else if (data.message) {
        textChunk = data.message
      } else if (data.llmNode) {
        textChunk = data.llmNode
      } else if (data.chunk) {
        textChunk = data.chunk
      } else if (data.delta) {
        textChunk = data.delta
      } else if (typeof data === 'string') {
        textChunk = data
      }

      // 添加文本块到响应中
      if (textChunk) {
        console.log('添加文本块:', textChunk)
        fullResponse += textChunk
        
        // 强制触发 Vue 响应式更新
        const messageIndex = currentChat.messages.findIndex(msg => msg.id === aiMessageId && msg.type === 'assistant')
        if (messageIndex !== -1) {
          currentChat.messages[messageIndex].content = fullResponse
          currentChat.messages[messageIndex].isStreaming = true
          
          // 强制触发响应式更新
          triggerRef(chatHistory)
          
          console.log('更新了 AI 消息，索引:', messageIndex, '类型:', currentChat.messages[messageIndex].type)
        } else {
          console.error('未找到 AI 消息，aiMessageId:', aiMessageId)
        }
        
        console.log('当前完整响应长度:', fullResponse.length)
        console.log('消息内容预览:', fullResponse.substring(0, 50) + '...')
        
        // 使用 nextTick 确保 DOM 更新后再滚动，AI回复时强制滚动
        nextTick(() => {
          scrollToBottom(true)
        })
      } else {
        console.log('未找到可处理的文本内容，数据结构:', Object.keys(data))
      }

    } catch (e) {
      console.error('处理 SSE 消息时出错:', e, '原始数据:', event.data)
    }
  }

  eventSource.onerror = (error) => {
    console.error('EventSource 错误:', error)
    eventSource.close()
    aiMessage.isStreaming = false

    if (fullResponse.trim()) {
      aiMessage.content = fullResponse
      aiMessage.status = '[状态] 部分完成（连接中断）'
    } else {
      const errorMessage = `❌ **请求失败**\n\n无法连接到后端服务，请检查:\n1. 后端服务是否运行在8081端口\n2. 网络连接是否正常\n3. 后端是否支持 CORS`
      aiMessage.content = errorMessage
      aiMessage.status = '[状态] 连接错误'
    }

    isLoading.value = false
    scrollToBottom()
  }

  eventSource.onopen = () => {
    console.log('EventSource 连接已建立')
    aiMessage.status = '[状态] 已连接，等待数据...'
    scrollToBottom()
  }

  // 监听自定义结束事件
  eventSource.addEventListener('end', () => {
    console.log('收到结束事件')
    aiMessage.content = fullResponse
    aiMessage.status = '[状态] 已完成'
    aiMessage.isStreaming = false
    eventSource.close()
    isLoading.value = false
    scrollToBottom()
  })

  // 设置超时处理（60秒）
  const timeoutId = setTimeout(() => {
    if (eventSource.readyState !== EventSource.CLOSED) {
      console.log('请求超时，关闭连接')
      eventSource.close()
      aiMessage.isStreaming = false

      if (fullResponse.trim()) {
        aiMessage.content = fullResponse
        aiMessage.status = '[状态] 部分完成（超时）'
      } else {
        const timeoutMessage = `❌ **请求超时**\n\n请求超时（60秒），请检查:\n1. 后端服务状态\n2. 网络连接稳定性\n3. 请求是否过于复杂`
        aiMessage.content = timeoutMessage
        aiMessage.status = '[状态] 请求超时'
      }

      isLoading.value = false
      scrollToBottom()
    }
  }, 600000)

  // 在连接关闭时清除超时
  const originalClose = eventSource.close.bind(eventSource)
  eventSource.close = () => {
    clearTimeout(timeoutId)
    originalClose()
  }
}
// simulateAIResponse function removed - not used in current implementation

// fallbackResponse function removed - not used in current implementation

const formatTime = (date) => {
  return date.toLocaleTimeString('zh-CN', {
    hour: '2-digit',
    minute: '2-digit',
  })
}

// 获取连接状态文本
const getConnectionStatusText = () => {
  switch (sseConnectionStatus.value) {
    case 'connected':
      return '已连接'
    case 'connecting':
      return '连接中...'
    case 'disconnected':
      return '未连接'
    default:
      return '未知状态'
  }
}

const formatOutput = (output) => {
  if (typeof output === 'string') {
    return output.length > 100 ? output.substring(0, 100) + '...' : output
  } else if (typeof output === 'object') {
    return JSON.stringify(output, null, 2)
  }
  return String(output)
}

const toggleOutput = (nodeId) => {
  // 首先验证节点是否存在
  const nodeExists = workflowNodes.value.some((node) => node.id === nodeId)
  if (!nodeExists) {
    return
  }

  const index = expandedOutputs.value.indexOf(nodeId)
  if (index > -1) {
    expandedOutputs.value.splice(index, 1)
  } else {
    expandedOutputs.value.push(nodeId)
  }
}

const toggleNodeExpand = (nodeId) => {
  const index = expandedNodes.value.indexOf(nodeId)
  if (index > -1) {
    expandedNodes.value.splice(index, 1)
  } else {
    // 确保节点存在才添加到展开列表
    const nodeExists = workflowNodes.value.some((node) => node.id === nodeId)
    if (nodeExists) {
      expandedNodes.value.push(nodeId)
    }
  }
}

const removeNode = (nodeId) => {
  const index = workflowNodes.value.findIndex((node) => node.id === nodeId)
  if (index > -1) {
    workflowNodes.value.splice(index, 1)

    // 清理所有相关的状态
    const cleanExpandedArray = (array) => {
      const idx = array.indexOf(nodeId)
      if (idx > -1) {
        array.splice(idx, 1)
      }
    }

    cleanExpandedArray(expandedNodes.value)
    cleanExpandedArray(expandedOutputs.value)
  }
}

const copyNodeContent = (node) => {
  const content = `${node.name}: ${node.description}`
  navigator.clipboard.writeText(content)
}

// 监听工作流节点变化，自动滚动到底部
watch(
  workflowNodes,
  () => {
    if (autoScrollEnabled.value && workflowContainer.value) {
      nextTick(() => {
        workflowContainer.value.scrollTop = workflowContainer.value.scrollHeight
      })
    }
  },
  { deep: true },
)

// 监听消息变化，自动滚动到底部
watch(
  messages,
  () => {
    nextTick(() => {
      scrollToBottom(true)
    })
  },
  { deep: true }
)

const handleKeyPress = (event) => {
  if (event.key === 'Enter' && !event.shiftKey) {
    event.preventDefault()
    sendMessage()
  }
}

// 自动调整文本框高度
const autoResizeTextarea = (textarea) => {
  if (!textarea) return

  // 重置高度以获取正确的滚动高度
  textarea.style.height = 'auto'

  // 设置新的高度，但限制最大高度
  const newHeight = Math.min(textarea.scrollHeight, 120)
  textarea.style.height = newHeight + 'px'

  // 如果达到最大高度，启用滚动
  if (newHeight >= 120) {
    textarea.style.overflowY = 'auto'
  } else {
    textarea.style.overflowY = 'hidden'
  }
}

// 监听输入变化
watch(inputMessage, () => {
  nextTick(() => {
    const textarea = document.querySelector('.message-input')
    if (textarea) {
      autoResizeTextarea(textarea)
    }
  })
})

const connectSSE = () => {
  try {
    console.log('开始连接 SSE，知识搜索监听器将被设置')
    
    const connectionTimeout = setTimeout(() => {
      if (sseConnection.value && sseConnection.value.readyState !== EventSource.OPEN) {
        sseConnection.value.close()
        sseConnectionStatus.value = 'disconnected'

        workflowNodes.value.push({
          id: Date.now(),
          name: '连接超时',
          description: 'SSE 连接超时，请检查后端服务是否正常运行',
          status: 'error',
          timestamp: new Date(),
        })
      }
    }, 10000)

    const eventSource = new EventSource('http://localhost:8081/sse/subscribe')
    console.log('SSE 连接已创建，URL: http://localhost:8081/sse/subscribe')

    eventSource.onopen = (event) => {
      clearTimeout(connectionTimeout)
    }

    eventSource.addEventListener('nodeOutput', (event) => {
      try {
        const data = JSON.parse(event.data)
        console.log('收到 nodeOutput 事件:', data)
        
        if (data && data.nodeName) {
          if (data.nodeName === "知识库搜索") {
            console.log('检测到知识库搜索节点，输出内容:', data.output)
            
            // 创建新的数组引用来强制触发响应式更新
            const newItem = {
              description: data.output || '知识搜索结果'
            }
            
            knowledgeItems.value = [...knowledgeItems.value, newItem]
            
            // 使用 nextTick 确保DOM更新
            nextTick(() => {
              console.log('已向 knowledgeItems 添加，当前数量:', knowledgeItems.value.length)
              console.log('当前 knowledgeItems 内容:', knowledgeItems.value)
            })
          } else {
            workflowNodes.value.push({
              id: Date.now(),
              name: data.nodeName,
              description: `节点 ${data.nodeName} 已完成`,
              status: 'completed',
              timestamp: new Date(),
            })
          }
        }
      } catch (e) {
        console.error('解析 nodeOutput 事件失败:', e, '原始数据:', event.data)
      }
    })

    eventSource.addEventListener('connected', (event) => {
      // 连接成功
    })

    eventSource.addEventListener('graphComplete', (event) => {
      workflowNodes.value.push({
        id: Date.now(),
        name: '工作流',
        description: event.data,
        status: 'completed',
        timestamp: new Date(),
      })
    })

    eventSource.addEventListener('graphError', (event) => {
      workflowNodes.value.push({
        id: Date.now(),
        name: '工作流',
        description: `错误: ${event.data}`,
        status: 'error',
        timestamp: new Date(),
      })
    })

    eventSource.addEventListener('toolInvoke', (event) => {
      const nodeId = Date.now()
      const nodeData = {
        id: nodeId,
        name: '工具调用',
        description: `工具: ${event.data}`,
        status: 'running',
        timestamp: new Date(),
      }

      workflowNodes.value.push(nodeData)

      setTimeout(() => {
        const nodeIndex = workflowNodes.value.findIndex((node) => node.id === nodeId)
        if (nodeIndex > -1) {
          workflowNodes.value[nodeIndex].status = 'completed'
        }
      }, 1000)
    })

    eventSource.onerror = (error) => {
      workflowNodes.value.push({
        id: Date.now(),
        name: '连接错误',
        description: `SSE 连接已断开，请检查后端服务`,
        status: 'error',
        timestamp: new Date(),
      })

      if (eventSource.readyState === EventSource.CLOSED) {
        setTimeout(() => {
          if (sseConnectionStatus.value !== 'connected') {
            connectSSE()
          }
        }, 5000)
      }
    }

    sseConnection.value = eventSource

    startConnectionMonitoring()
  } catch (error) {
    workflowNodes.value.push({
      id: Date.now(),
      name: '连接失败',
      description: `无法创建 SSE 连接: ${error.message}`,
      status: 'error',
      timestamp: new Date(),
    })
  }
}

// 连接状态监控函数
const monitorSSEConnection = () => {
  console.log('Monitoring SSE connection...')

  if (sseConnection.value) {
    const readyState = sseConnection.value.readyState
    console.log('Current SSE readyState:', readyState)

    // 更新连接状态
    switch (readyState) {
      case EventSource.CONNECTING:
        if (sseConnectionStatus.value !== 'connecting') {
          sseConnectionStatus.value = 'connecting'
          console.log('SSE connection status: connecting')

          // 显示连接中状态
          workflowNodes.value.push({
            id: Date.now(),
            name: '连接中',
            description: '正在尝试连接到后端服务...',
            status: 'running',
            timestamp: new Date(),
          })
        }
        break
      case EventSource.OPEN:
        if (sseConnectionStatus.value !== 'connected') {
          sseConnectionStatus.value = 'connected'
          console.log('SSE connection status: connected')

          // 删除所有连接中的节点（包括"连接中"和"手动重连"）
          const connectingNodeIndices = []
          workflowNodes.value.forEach((node, index) => {
            if ((node.name === '连接中' || node.name === '手动重连') && node.status === 'running') {
              connectingNodeIndices.push(index)
            }
          })

          // 从后往前删除，避免索引变化问题
          connectingNodeIndices.reverse().forEach((index) => {
            workflowNodes.value.splice(index, 1)
          })

          // 显示连接成功状态
          workflowNodes.value.push({
            id: Date.now(),
            name: '连接成功',
            description: '已成功连接到后端服务',
            status: 'completed',
            timestamp: new Date(),
          })
        }
        break
      case EventSource.CLOSED:
        if (sseConnectionStatus.value !== 'disconnected') {
          sseConnectionStatus.value = 'disconnected'
          console.log('SSE connection status: disconnected')
        }
        break
    }
  } else {
    if (sseConnectionStatus.value !== 'disconnected') {
      sseConnectionStatus.value = 'disconnected'
      console.log('SSE connection status: disconnected (no connection)')
    }
  }
}

// 启动连接监控
const startConnectionMonitoring = () => {
  console.log('Starting SSE connection monitoring...')

  // 立即执行一次监控
  monitorSSEConnection()

  // 改为每5秒监控一次连接状态，提高响应速度
  connectionMonitorInterval.value = setInterval(() => {
    monitorSSEConnection()
  }, 5000)
}

// 停止连接监控
const stopConnectionMonitoring = () => {
  console.log('Stopping SSE connection monitoring...')

  if (connectionMonitorInterval.value) {
    clearInterval(connectionMonitorInterval.value)
    connectionMonitorInterval.value = null
  }
}

// 手动重连
const reconnectSSE = () => {
  if (isReconnecting.value) return

  isReconnecting.value = true
  console.log('Manual reconnection initiated...')

  // 清理现有连接
  if (sseConnection.value) {
    sseConnection.value.close()
    sseConnection.value = null
  }

  // 重置连接状态
  sseConnectionStatus.value = 'disconnected'

  // 显示重连状态
  workflowNodes.value.push({
    id: Date.now(),
    name: '手动重连',
    description: '正在重新连接到后端服务...',
    status: 'running',
    timestamp: new Date(),
  })

  // 延迟执行重连
  setTimeout(() => {
    connectSSE()
    isReconnecting.value = false
  }, 1000)
}

onMounted(() => {
  console.log('组件已挂载，初始化知识搜索数据:', knowledgeItems.value.length)
  scrollToBottom()
  connectSSE()

  // 初始化文本框自动调整
  nextTick(() => {
    const textarea = document.querySelector('.message-input')
    if (textarea) {
      autoResizeTextarea(textarea)

      // 添加输入事件监听器
      textarea.addEventListener('input', () => {
        autoResizeTextarea(textarea)
      })
    }
  })
})

onUpdated(() => {
  // 在组件更新时重新初始化文本框自动调整
  nextTick(() => {
    const textarea = document.querySelector('.message-input')
    if (textarea) {
      autoResizeTextarea(textarea)
    }
  })
})

const createNewChat = () => {
  const newChatId = Math.max(...chatHistory.value.map((chat) => chat.id)) + 1
  const newChat = {
    id: newChatId,
    title: `新对话 ${newChatId - 1}`,
    preview: '点击开始新的对话...',
    messages: [
      {
        id: 1,
        type: 'assistant',
        content:
          '你好！我是智能运维助手，专注于系统监控、故障诊断和性能优化。我可以帮助你进行系统巡检、分析日志、优化性能、解决问题等。有什么需要我协助的吗？',
        timestamp: new Date(),
      },
    ],
    isActive: true,
  }

  // Deactivate all other chats
  chatHistory.value.forEach((chat) => {
    chat.isActive = false
  })

  chatHistory.value.unshift(newChat)
  currentChatId.value = newChatId
  inputMessage.value = ''

  scrollToBottom()
}

const switchChat = (chatId) => {
  // Deactivate all chats
  chatHistory.value.forEach((chat) => {
    chat.isActive = chat.id === chatId
  })

  currentChatId.value = chatId
  inputMessage.value = ''

  // 切换聊天后强制滚动到底部
  nextTick(() => {
    scrollToBottom(true)
  })
}

const startInspection = () => {
  if (isInspectionRunning.value) return

  isInspectionRunning.value = true

  // Add inspection message
  const inspectionMessage = {
    id: Date.now(),
    type: 'assistant',
    content: '🔍 **开始系统巡检**\n\n正在对系统进行全面检查，请稍候...',
    timestamp: new Date(),
  }

  const currentChat = chatHistory.value.find((chat) => chat.id === currentChatId.value)
  if (currentChat) {
    currentChat.messages.push(inspectionMessage)
  }

  scrollToBottom()

  // Send GET request to backend
  fetch('http://localhost:8081/inspect', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
  })
    .then((response) => {
      if (!response.ok) {
        throw new Error(`HTTP error! status: ${response.status}`)
      }
      return response.text()
    })
    .then((markdownContent) => {
      // Backend returns markdown content directly
      const inspectionResults = {
        id: Date.now(),
        type: 'assistant',
        content: `🔍 **巡检完成**\n\n${markdownContent}`,
        timestamp: new Date(),
      }

      if (currentChat) {
        currentChat.messages.push(inspectionResults)
      }

      isInspectionRunning.value = false
      scrollToBottom()
    })
    .catch((error) => {
      console.error('Inspection failed:', error)

      // Show error message
      const errorMessage = {
        id: Date.now(),
        type: 'assistant',
        content: `❌ **巡检失败**\n\n无法连接到后端服务，请检查:\n1. 后端服务是否运行在8081端口\n2. 网络连接是否正常\n\n错误信息: ${error.message}`,
        timestamp: new Date(),
      }

      if (currentChat) {
        currentChat.messages.push(errorMessage)
      }

      isInspectionRunning.value = false
      scrollToBottom()
    })
}

onUnmounted(() => {
  // 停止连接监控
  stopConnectionMonitoring()

  // 清理文本框事件监听器
  const textarea = document.querySelector('.message-input')
  if (textarea) {
    textarea.removeEventListener('input', () => {
      autoResizeTextarea(textarea)
    })
  }
})
</script>

<template>
  <div class="chat-container">
    <!-- Sidebar -->
    <aside class="sidebar">
      <div class="sidebar-content">
        <div class="sidebar-header">
          <button class="new-chat-btn" @click="createNewChat">+ 新对话</button>
        </div>

        <div class="chat-history">
          <div
            v-for="chat in chatHistory"
            :key="chat.id"
            :class="['history-item', { active: chat.isActive }]"
            @click="switchChat(chat.id)"
          >
            <div class="history-title">{{ chat.title }}</div>
            <div class="history-preview">{{ chat.preview }}</div>
          </div>
        </div>
      </div>

      <!-- Knowledge Search Carousel at Bottom -->
      <div class="knowledge-carousel-section bottom">
        <div class="carousel-header">
          <h3>知识库搜索</h3>
          <div class="status-indicator">
            <span class="pulse-dot"></span>
          </div>
        </div>
        <div class="carousel-container" style="height: 250px">
          <KnowledgeCarousel 
            :items="knowledgeItems" 
            :speed="60" 
            :height="35" 
            :key="knowledgeItems.length"
          />
        </div>
      </div>
    </aside>

    <!-- Main Content Area -->
    <div class="main-content">
      <!-- Header -->
      <header class="chat-header">
        <div class="header-left">
          <div class="logo">
            <div class="logo-icon">🔧</div>
            <h1>智能运维助手</h1>
          </div>
        </div>
        <div class="header-right">
          
          <button class="icon-btn upload-knowledge-btn" @click="showUploadModal = true">
            <span class="btn-icon">📚</span>
            <span class="btn-text">上传知识库</span>
          </button>
          <button class="icon-btn inspection-btn" @click="sendReport">
            <span class="btn-icon">🔍</span>
            <span class="btn-text">一键巡检</span>
          </button>
          <div class="connection-status" :class="sseConnectionStatus">
            <span class="status-indicator"></span>
            <span class="status-text">{{ getConnectionStatusText() }}</span>
            <button
              v-if="sseConnectionStatus !== 'connected'"
              @click="reconnectSSE"
              class="reconnect-btn"
              :disabled="isReconnecting"
            >
              {{ isReconnecting ? '重连中...' : '重连' }}
            </button>
          </div>
        </div>
      </header>

      <!-- Chat Messages -->
      <main class="chat-main">
        <div class="messages-container">
          <div
            v-for="message in messages"
            :key="message.id"
            :class="['message', message.type]"
            :style="{
              '--random-offset': Math.random() * 0.6 - 0.3,
            }"
          >
            <div class="message-avatar" v-if="message.type === 'assistant'">
              <div class="ai-avatar">🤖</div>
            </div>
            <div class="message-content" :class="{ 'user-content': message.type === 'user' }">
              <div class="message-text">
                <MarkdownRenderer
                  :content="message.content"
                  :is-streaming="message.isStreaming"
                />
              </div>
              <div v-if="message.status && message.type === 'assistant'" class="message-status">
                {{ message.status }}
              </div>
              <div class="message-time">{{ formatTime(message.timestamp) }}</div>
            </div>
          </div>



          <div ref="messagesEndRef"></div>
        </div>
      </main>

      <!-- Input Area -->
      <div class="input-area">
        <div class="input-container">
          <textarea
            v-model="inputMessage"
            @keypress="handleKeyPress"
            placeholder="输入消息..."
            class="message-input"
            rows="1"
            :disabled="isLoading"
          ></textarea>
          <button
            @click="sendMessage"
            :disabled="!inputMessage.trim() || isLoading"
            class="send-btn"
          >
            发送
          </button>
        </div>
        <div class="input-info">
          <span class="char-count">{{ inputMessage.length }}/4000</span>
          <span class="hint">按 Enter 发送，Shift+Enter 换行</span>
        </div>
      </div>
    </div>

    <!-- Right Sidebar - Workflow Toolbar -->
    <aside class="workflow-sidebar">
      <div class="workflow-header">
        <h3>工作流节点</h3>
        <div class="header-controls">
          <button @click="workflowNodes = []" class="clear-btn">清空</button>
        </div>
      </div>
      <div class="workflow-container" ref="workflowContainer">
        <div
          v-for="(node, index) in workflowNodes"
          :key="node.id"
          :class="['workflow-node', node.status, { expanded: expandedNodes.includes(node.id) }]"
          :style="{
            '--random-offset': Math.random() * 0.6 - 0.3,
            '--delay': `${index * 0.1}s`,
          }"
          @click="toggleNodeExpand(node.id)"
        >
          <div class="node-connector" v-if="index > 0"></div>
          <div class="node-icon">
            <span v-if="node.status === 'running'">⚡</span>
            <span v-else-if="node.status === 'completed'">✅</span>
            <span v-else-if="node.status === 'error'">❌</span>
            <span v-else>⏳</span>
          </div>
          <div class="node-content">
            <div class="node-header">
              <div class="node-name">{{ node.name }}</div>
              <div class="node-actions">
                <button @click.stop="removeNode(node.id)" class="node-action-btn remove-btn">
                  <span>✕</span>
                </button>
                <button @click.stop="copyNodeContent(node)" class="node-action-btn copy-btn">
                  <span>📋</span>
                </button>
              </div>
            </div>
            <div class="node-description" v-if="node.status === 'error'">
              <span class="error-text">{{ node.description }}</span>
            </div>
            <div class="node-description" v-else-if="node.output">
              <div class="output-preview" :class="{ expanded: expandedOutputs.includes(node.id) }">
                {{ formatOutput(node.output) }}
              </div>
              <button
                @click.stop="toggleOutput(node.id)"
                class="toggle-output-btn"
                :class="{ expanded: expandedOutputs.includes(node.id) }"
              >
                {{ expandedOutputs.includes(node.id) ? '收起' : '展开' }}
              </button>
            </div>
            <div class="node-description" v-else>
              {{ node.description }}
            </div>
            <div class="node-footer">
              <div class="node-time">{{ formatTime(node.timestamp) }}</div>
              <div class="node-progress" v-if="node.status === 'running'">
                <div class="progress-bar"></div>
              </div>
            </div>
          </div>
          <div class="node-status-indicator"></div>
        </div>
        <div v-if="workflowNodes.length === 0" class="empty-state">
          <div class="empty-icon">🔄</div>
          <div class="empty-text">等待工作流节点...</div>
        </div>
      </div>
    </aside>

    <!-- Upload Modal -->
    <div v-if="showUploadModal" class="modal-overlay" @click="showUploadModal = false">
      <div class="modal-content" @click.stop>
        <div class="modal-header">
          <h2>上传知识库</h2>
          <button class="close-btn" @click="showUploadModal = false">×</button>
        </div>
        <div class="modal-body">
          <UploadKnowledgeBase @upload-complete="showUploadModal = false" />
        </div>
      </div>
    </div>
  </div>
</template>

<style  scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100vh;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #0a0a0a;
  font-family: 'Courier New', monospace;
}

.chat-container {
  height: 100vh;
  background:
    linear-gradient(135deg, rgba(0, 255, 255, 0.1) 0%, rgba(255, 0, 255, 0.1) 100%),
    radial-gradient(circle at 20% 80%, rgba(0, 255, 255, 0.2) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255, 0, 255, 0.2) 0%, transparent 50%),
    radial-gradient(circle at 40% 40%, rgba(0, 255, 255, 0.1) 0%, transparent 50%);
  font-family: 'Courier New', monospace;
  display: flex;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border: 2px solid #00ffff;
  box-shadow:
    0 0 30px rgba(0, 255, 255, 0.3),
    0 0 60px rgba(255, 0, 255, 0.2),
    inset 0 0 30px rgba(0, 0, 0, 0.5);
  border-radius: 25px;
}

@keyframes neonGlow {
  0%,
  100% {
    text-shadow:
      0 0 5px #00ffff,
      0 0 10px #00ffff,
      0 0 15px #00ffff,
      0 0 20px #00ffff;
  }
  50% {
    text-shadow:
      0 0 10px #00ffff,
      0 0 20px #00ffff,
      0 0 30px #00ffff,
      0 0 40px #00ffff;
  }
}

@keyframes dataStream {
  0% {
    transform: translateY(-100%);
  }
  100% {
    transform: translateY(100%);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.4;
  }
  50% {
    opacity: 1;
  }
}

@keyframes scanLine {
  0% {
    transform: translateY(-100%);
  }
  100% {
    transform: translateY(100%);
  }
}

/* Header */
.chat-header {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 25px;
  margin-bottom: 0;
  position: relative;
  z-index: 2;
  transform: none;
  animation: none;
  border: 2px solid #00ffff;
  backdrop-filter: blur(5px);
  box-shadow:
    0 4px 15px rgba(0, 255, 255, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  padding: 1rem 2rem;
  height: auto;
  min-height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-left {
  display: flex;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  font-size: 1.5rem;
  filter: drop-shadow(0 0 10px #00ffff);
  animation: pulse 2s ease-in-out infinite;
}

.logo h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: #00ffff;
  text-shadow:
    0 0 10px #00ffff,
    0 0 20px #00ffff,
    0 0 30px #00ffff;
  animation: neonGlow 2s ease-in-out infinite;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.icon-btn {
  background: linear-gradient(135deg, rgba(0, 255, 255, 0.1) 0%, rgba(255, 0, 255, 0.1) 100%);
  border: 1px solid #00ffff;
  color: #00ffff;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 20px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
  backdrop-filter: blur(5px);
  box-shadow:
    0 4px 15px rgba(0, 255, 255, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.icon-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(0, 255, 255, 0.4), transparent);
  transition: left 0.6s ease;
}

.typewriter-toggle-btn,
.upload-knowledge-btn,
.inspection-btn {
  background: linear-gradient(135deg, rgba(0, 255, 255, 0.2) 0%, rgba(255, 0, 255, 0.2) 100%);
  border: 1px solid #00ffff;
  padding: 0.5rem 1rem;
}

.typewriter-toggle-btn:hover,
.upload-knowledge-btn:hover,
.inspection-btn:hover {
  background: linear-gradient(135deg, rgba(0, 255, 255, 0.3) 0%, rgba(255, 0, 255, 0.3) 100%);
  color: #ffffff;
  box-shadow:
    0 6px 20px rgba(0, 255, 255, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transform: none;
}

.typewriter-toggle-btn:hover::before,
.upload-knowledge-btn:hover::before,
.inspection-btn:hover::before {
  left: 100%;
}

.btn-text {
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  text-shadow: 0 0 5px rgba(0, 255, 255, 0.5);
}

.inspection-btn {
  background: linear-gradient(135deg, rgba(255, 0, 255, 0.2) 0%, rgba(0, 255, 255, 0.2) 100%);
  border-color: #ff00ff;
  color: #ff00ff;
}

.inspection-btn:hover {
  background: linear-gradient(135deg, rgba(255, 0, 255, 0.3) 0%, rgba(0, 255, 255, 0.3) 100%);
  color: #ffffff;
  border-color: #ff00ff;
  box-shadow:
    0 6px 20px rgba(255, 0, 255, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.icon-btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(59, 130, 246, 0.1);
  border-radius: 60px;
  transform: translate(-50%, -50%);
  transition: all 0.4s ease;
}

.icon-btn:hover {
  background: linear-gradient(135deg, rgba(0, 255, 255, 0.2) 0%, rgba(255, 0, 255, 0.2) 100%);
  color: #ffffff;
  box-shadow:
    0 6px 20px rgba(0, 255, 255, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.icon-btn:hover::before {
  left: 100%;
}

.icon-btn:active {
  transform: translateY(0) scale(0.95);
}

.user-avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  border-radius: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 0.875rem;
  transition: all 0.2s ease;
  cursor: pointer;
}

.user-avatar::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 60px;
  transform: translate(-50%, -50%);
  transition: all 0.4s ease;
}

.user-avatar:hover {
  transform: scale(1.1) rotate(5deg);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

.user-avatar:hover::before {
  width: 100%;
  height: 100%;
}

.user-avatar:active {
  transform: scale(0.95) rotate(0deg);
}

/* Main Content Area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  z-index: 10;
  height: 100vh;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 20px;
  margin: 0 1rem;
  backdrop-filter: blur(5px);
  border: 2px solid rgba(0, 255, 255, 0.3);
  min-height: 0;
  gap: 0;
}

/* Add circuit texture to main content */
.main-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image:
    radial-gradient(circle at 15% 15%, rgba(0, 255, 255, 0.08) 1px, transparent 1px),
    radial-gradient(circle at 85% 85%, rgba(255, 0, 255, 0.08) 1px, transparent 1px),
    linear-gradient(45deg, transparent 49%, rgba(0, 255, 255, 0.03) 50%, transparent 51%),
    linear-gradient(-45deg, transparent 49%, rgba(255, 0, 255, 0.03) 50%, transparent 51%);
  background-size:
    40px 40px,
    25px 25px,
    30px 30px,
    20px 20px;
  background-position:
    0 0,
    20px 20px,
    0 0,
    0 0;
  animation: circuitMove 25s linear infinite;
  pointer-events: none;
  z-index: 1;
  opacity: 0.5;
}

/* Main Chat Area */
.chat-main {
  flex: 1;
  overflow: hidden;
  display: flex;
  min-height: 0; /* 防止flex项目溢出 */
  position: relative;
  margin-bottom: 0;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1rem 0 1rem;
  width: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 255, 255, 0.2);
  border-radius: 20px;
  position: relative;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
  min-height: 0;
}

.message {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  animation: glitchIn 0.7s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: bottom left;
  position: relative;
  z-index: 10;
  transform: none;
  transition: none;
}

.message::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(0, 255, 255, 0.05) 0%, rgba(255, 0, 255, 0.05) 100%);
  border-radius: 12px;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: -1;
}

.message:hover::before {
  opacity: 1;
}

.message.user {
  justify-content: flex-end;
}

.message.user .message-content {
  text-align: right;
  width: fit-content;
  max-width: 70%;
  margin-left: auto;
  display: inline-block;
}

.message.user .message-text {
  text-align: left;
}

@keyframes glitchIn {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
}

.ai-avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #ff00ff 0%, #00ffff 100%);
  border-radius: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  color: white;
  box-shadow:
    0 4px 15px rgba(255, 0, 255, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  animation: pulse 2s ease-in-out infinite;
  border: 2px solid rgba(0, 255, 255, 0.3);
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-text {
  color: #ffffff;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 0.95rem;
  text-shadow: 0 0 3px rgba(0, 255, 255, 0.3);
}

.message-time {
  font-size: 0.75rem;
  color: #00ffff;
  margin-top: 0.25rem;
  text-shadow: 0 0 3px rgba(0, 255, 255, 0.5);
  font-family: 'Courier New', monospace;
}

.message.user .message-text {
  background:
    linear-gradient(135deg, rgba(0, 255, 255, 0.2) 0%, rgba(255, 0, 255, 0.2) 100%),
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 3px,
      rgba(0, 255, 255, 0.1) 3px,
      rgba(0, 255, 255, 0.1) 6px
    );
  border: 1px solid #00ffff;
  padding: 0.5rem 0.75rem;
  border-radius: 0 20px 20px 20px;
  color: #00ffff;
  transition: all 0.3s ease;
  position: relative;
  display: inline-block;
  min-width: fit-content;
  backdrop-filter: blur(5px);
  box-shadow:
    0 4px 15px rgba(0, 255, 255, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  text-shadow: 0 0 5px rgba(0, 255, 255, 0.5);
  transform: none;
}

.message.user .message-text::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, #00ffff, #ff00ff);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s ease;
}

.message.user .message-text:hover::before {
  transform: scaleX(1);
}

.message.user .message-text:hover {
  box-shadow:
    0 6px 20px rgba(0, 255, 255, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transform: none;
}

.message.user .message-text:hover::before {
  transform: scaleX(1);
}

.message.assistant .message-text {
  background:
    rgba(0, 0, 0, 0.6),
    repeating-linear-gradient(
      -45deg,
      transparent,
      transparent 4px,
      rgba(255, 0, 255, 0.1) 4px,
      rgba(255, 0, 255, 0.1) 8px
    );
  border: 1px solid rgba(255, 0, 255, 0.3);
  padding: 0.75rem;
  border-radius: 20px 0 20px 20px;
  box-shadow:
    0 4px 15px rgba(255, 0, 255, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transition: all 0.3s ease;
  position: relative;
  backdrop-filter: blur(5px);
  color: #ffffff;
  transform: none;
}

.message.assistant .message-text::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, #ff00ff, #00ffff);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s ease;
}

.message.assistant .message-text:hover::before {
  transform: scaleX(1);
}

.message.assistant .message-text:hover {
  box-shadow:
    0 6px 20px rgba(255, 0, 255, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transform: none;
}

.message.assistant .message-text:hover::before {
  transform: scaleX(1);
}

.message.assistant .message-text:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

/* Loading Indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 0, 255, 0.3);
  border-radius: 20px;
  box-shadow:
    0 4px 15px rgba(255, 0, 255, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(5px);
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: linear-gradient(135deg, #00ffff 0%, #ff00ff 100%);
  border-radius: 60px;
  animation: typing 1.4s infinite;
  box-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
}

.typing-indicator span:nth-child(1) {
  animation-delay: 0s;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-3px);
  }
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(59, 130, 246, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
  }
}

@keyframes rainbowShift {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

@keyframes rainbowFlow {
  0% {
    background-position: 0% 50%;
  }
  100% {
    background-position: 200% 50%;
  }
}

@keyframes neonGlow {
  0% {
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
  }
  100% {
    text-shadow:
      0 0 30px rgba(255, 255, 255, 0.8),
      0 0 40px rgba(59, 130, 246, 0.6);
  }
}

@keyframes logoFloat {
  0%,
  100% {
    transform: translateY(0px) rotate(0deg);
  }
  25% {
    transform: translateY(-3px) rotate(5deg);
  }
  75% {
    transform: translateY(3px) rotate(-5deg);
  }
}

@keyframes activePulse {
  0%,
  100% {
    box-shadow:
      0 0 20px rgba(59, 130, 246, 0.4),
      0 0 40px rgba(59, 130, 246, 0.2),
      inset 0 0 20px rgba(59, 130, 246, 0.1);
  }
  50% {
    box-shadow:
      0 0 30px rgba(59, 130, 246, 0.6),
      0 0 60px rgba(59, 130, 246, 0.3),
      inset 0 0 30px rgba(59, 130, 246, 0.2);
  }
}

@keyframes inputGlow {
  0%,
  100% {
    box-shadow:
      0 0 20px rgba(59, 130, 246, 0.4),
      0 0 40px rgba(59, 130, 246, 0.2),
      0 0 60px rgba(59, 130, 246, 0.1),
      inset 0 0 20px rgba(59, 130, 246, 0.1);
  }
  50% {
    box-shadow:
      0 0 30px rgba(59, 130, 246, 0.6),
      0 0 60px rgba(59, 130, 246, 0.3),
      0 0 90px rgba(59, 130, 246, 0.2),
      inset 0 0 30px rgba(59, 130, 246, 0.2);
  }
}

@keyframes avatarFloat {
  0%,
  100% {
    transform: translateY(0px) rotate(0deg) scale(1);
  }
  25% {
    transform: translateY(-4px) rotate(3deg) scale(1.05);
  }
  75% {
    transform: translateY(4px) rotate(-3deg) scale(0.95);
  }
}

/* Input Area */
.input-area {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 25px;
  margin: 0;
  padding: 1rem 1.5rem;
  height: auto;
  min-height: 120px;
  flex-shrink: 0;
  backdrop-filter: blur(5px);
  border: 2px solid #ff00ff;
  box-shadow:
    0 4px 15px rgba(255, 0, 255, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  margin-top: 0;
}

.input-container {
  display: flex;
  gap: 1rem;
  align-items: stretch;
  padding: 0 1.5rem;
  height: 100%;
  width: 100%;
  min-height: 80px;
}

.message-input {
  flex: 1;
  background: rgba(0, 0, 0, 0.6);
  border: 2px solid rgba(0, 255, 255, 0.3);
  border-radius: 20px;
  color: #00ffff;
  padding: 1rem;
  resize: none;
  outline: none;
  font-family: 'Courier New', monospace;
  font-size: 1rem;
  line-height: 1.5;
  min-height: 60px;
  max-height: 120px;
  transition: all 0.3s ease;
  position: relative;
  backdrop-filter: blur(5px);
  text-shadow: 0 0 5px rgba(0, 255, 255, 0.5);
  /* 隐藏滚动条但保持滚动功能 */
  overflow: auto;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE and Edge */
  flex-grow: 1;
  width: 100%;
  box-sizing: border-box;
}

.message-input::placeholder {
  color: rgba(0, 255, 255, 0.5);
  text-shadow: 0 0 3px rgba(0, 255, 255, 0.3);
}

.message-input:focus {
  border-color: #00ffff;
  box-shadow:
    0 0 20px rgba(0, 255, 255, 0.4),
    0 0 40px rgba(0, 255, 255, 0.2),
    inset 0 0 20px rgba(0, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.8);
}

.message-input::placeholder {
  color: #9ca3af;
}

.message-input::placeholder {
  color: #9ca3af;
}

.send-btn {
  background: linear-gradient(135deg, #00ffff 0%, #ff00ff 100%);
  border: 2px solid #00ffff;
  border-radius: 20px;
  color: white;
  min-width: 70px;
  height: auto;
  min-height: 48px;
  max-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.3s ease;
  flex-shrink: 0;
  box-shadow:
    0 4px 15px rgba(0, 255, 255, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  position: relative;
  overflow: hidden;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 0 1rem;
  align-self: center;
}

.send-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  transition: left 0.6s ease;
}

.send-btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 60px;
  transform: translate(-50%, -50%);
  transition: all 0.5s ease;
}

.send-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #00ffff 0%, #ff00ff 100%);
  border-color: #ffffff;
  box-shadow:
    0 6px 20px rgba(0, 255, 255, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.send-btn:hover:not(:disabled)::before {
  left: 100%;
}

.send-btn:active:not(:disabled) {
  transform: translateY(0) scale(0.95);
}

.send-btn:hover:not(:disabled)::before {
  width: 60px;
  height: 60px;
}

.send-btn:active:not(:disabled) {
  transform: scale(0.95) translateY(0);
}

.send-btn:disabled {
  background: linear-gradient(135deg, #666666 0%, #444444 100%);
  border-color: #666666;
  cursor: not-allowed;
  opacity: 0.5;
  box-shadow: none;
}

.input-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
  padding: 0 0.5rem;
  font-size: 0.75rem;
  color: rgba(0, 255, 255, 0.6);
  text-shadow: 0 0 3px rgba(0, 255, 255, 0.3);
}

/* Connection Status Display */
.connection-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  border-radius: 25px;
  font-size: 1rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  backdrop-filter: blur(5px);
  border: 2px solid;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  min-height: 48px;
}

.connection-status::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.6s ease;
}

.connection-status.connected {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.2) 0%, rgba(16, 185, 129, 0.1) 100%);
  border-color: #10b981;
  color: #10b981;
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.connection-status.connected::before {
  background: linear-gradient(90deg, transparent, rgba(16, 185, 129, 0.4), transparent);
}

.connection-status.connecting {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.2) 0%, rgba(245, 158, 11, 0.1) 100%);
  border-color: #f59e0b;
  color: #f59e0b;
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

.connection-status.connecting::before {
  background: linear-gradient(90deg, transparent, rgba(245, 158, 11, 0.4), transparent);
}

.connection-status.disconnected {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.2) 0%, rgba(239, 68, 68, 0.1) 100%);
  border-color: #ef4444;
  color: #ef4444;
  box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.connection-status.disconnected::before {
  background: linear-gradient(90deg, transparent, rgba(239, 68, 68, 0.4), transparent);
}

.connection-status:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0, 255, 255, 0.4);
}

.connection-status:hover::before {
  left: 100%;
}

.status-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  animation: pulse 2s ease-in-out infinite;
}

.status-indicator.connected {
  background: #10b981;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.8);
}

.status-indicator.connecting {
  background: #f59e0b;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.8);
  animation: pulse 1s ease-in-out infinite;
}

.status-indicator.disconnected {
  background: #ef4444;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.8);
}

.status-text {
  font-family: 'Courier New', monospace;
  text-shadow: 0 0 5px currentColor;
}

.reconnect-btn {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.2) 0%, rgba(245, 158, 11, 0.1) 100%);
  border: 2px solid #f59e0b;
  color: #f59e0b;
  padding: 0.5rem 1rem;
  border-radius: 16px;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin-left: 0.75rem;
  backdrop-filter: blur(5px);
  min-height: 36px;
}

.reconnect-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.3) 0%, rgba(245, 158, 11, 0.2) 100%);
  color: #ffffff;
  border-color: #f59e0b;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.reconnect-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.char-count {
  font-family: 'Courier New', monospace;
}

.hint {
  font-family: 'Courier New', monospace;
  opacity: 0.8;
}

/* Sidebar - Control Panel */
.sidebar {
  width: 280px;
  background:
    radial-gradient(ellipse at center, rgba(0, 20, 40, 0.95) 0%, rgba(0, 0, 0, 0.95) 100%),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 2px,
      rgba(0, 255, 255, 0.03) 2px,
      rgba(0, 255, 255, 0.03) 4px
    ),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(0, 255, 255, 0.02) 2px,
      rgba(0, 255, 255, 0.02) 4px
    );
  border-right: none;
  border-left: 3px solid #00ffff;
  border-radius: 0 20px 20px 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  backdrop-filter: blur(15px);
  box-shadow:
    4px 0 40px rgba(0, 255, 255, 0.6),
    inset -1px 0 0 rgba(255, 255, 255, 0.1),
    inset 1px 0 0 rgba(0, 255, 255, 0.1);
  position: relative;
  z-index: 5;
  transform: none;
  clip-path: none;
  /* 驾驶舱网格效果 */
  position: relative;
}

.sidebar-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image:
    linear-gradient(rgba(0, 255, 255, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 255, 255, 0.1) 1px, transparent 1px);
  background-size: 20px 20px;
  animation: gridMove 15s linear infinite;
  pointer-events: none;
  z-index: 1;
}

.sidebar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(0, 255, 255, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(0, 255, 255, 0.05) 0%, transparent 50%);
  animation: pulseGlow 4s ease-in-out infinite;
  pointer-events: none;
  z-index: 1;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 2px solid #00ffff;
  height: 80px;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  background:
    linear-gradient(135deg, rgba(0, 20, 40, 0.8) 0%, rgba(0, 0, 0, 0.8) 100%),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 10px,
      rgba(0, 255, 255, 0.05) 10px,
      rgba(0, 255, 255, 0.05) 11px
    );
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 2;
  /* 驾驶舱控制面板效果 */
  box-shadow:
    inset 0 2px 0 rgba(0, 255, 255, 0.3),
    inset 0 -2px 0 rgba(0, 255, 255, 0.1);
}

.sidebar-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, #00ffff, transparent);
  animation: scanLine 3s linear infinite;
}

.new-chat-btn {
  width: 100%;
  background:
    linear-gradient(135deg, rgba(0, 255, 255, 0.1) 0%, rgba(0, 255, 255, 0.2) 100%),
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 10px,
      rgba(0, 255, 255, 0.03) 10px,
      rgba(0, 255, 255, 0.03) 11px
    );
  border: 2px solid #00ffff;
  border-radius: 8px;
  color: #00ffff;
  padding: 0.75rem;
  cursor: pointer;
  font-size: 0.875rem;
  transition: all 0.3s ease;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  position: relative;
  overflow: hidden;
  box-shadow:
    0 4px 20px rgba(0, 255, 255, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    inset 0 -1px 0 rgba(0, 255, 255, 0.3);
  /* 驾驶舱按钮效果 */
  text-shadow: 0 0 10px rgba(0, 255, 255, 0.8);
  border-image: linear-gradient(45deg, #00ffff, #ff00ff, #00ffff) 1;
}

.new-chat-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  transition: left 0.6s ease;
}

.new-chat-btn::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(0, 255, 255, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: all 0.6s ease;
}

.new-chat-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  transition: left 0.6s ease;
}

.new-chat-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  transition: left 0.6s ease;
}

.new-chat-btn::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 60px;
  transform: translate(-50%, -50%);
  transition: all 0.6s ease;
}

.new-chat-btn:hover {
  background: linear-gradient(135deg, #00ffff 0%, #ff00ff 100%);
  border-color: #ffffff;
  box-shadow:
    0 6px 20px rgba(0, 255, 255, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.new-chat-btn:hover::before {
  left: 100%;
}

.new-chat-btn:hover::before {
  left: 100%;
}

.new-chat-btn:hover::after {
  width: 100%;
  height: 100%;
}

.new-chat-btn:active {
  transform: translateY(-1px) rotateX(2deg) scale(0.98);
}

.new-chat-btn:hover::before {
  left: 100%;
}

.new-chat-btn:active {
  transform: translateY(0);
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  position: relative;
  z-index: 2;
}

.history-item {
  background:
    linear-gradient(135deg, rgba(0, 20, 40, 0.6) 0%, rgba(0, 0, 0, 0.6) 100%),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 2px,
      rgba(0, 255, 255, 0.02) 2px,
      rgba(0, 255, 255, 0.02) 4px
    );
  border: 1px solid rgba(0, 255, 255, 0.3);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  backdrop-filter: blur(10px);
  /* 驾驶舱控制面板效果 */
  box-shadow:
    inset 0 1px 0 rgba(0, 255, 255, 0.2),
    inset 0 -1px 0 rgba(0, 255, 255, 0.1),
    0 4px 15px rgba(0, 0, 0, 0.3);
}

.history-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(0, 255, 255, 0.15) 0%, rgba(255, 0, 255, 0.15) 100%);
  border-radius: 8px;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: -1;
}

.history-item::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0, 255, 255, 0.5), transparent);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.history-item:hover {
  background:
    linear-gradient(135deg, rgba(0, 40, 80, 0.8) 0%, rgba(0, 0, 0, 0.8) 100%),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 2px,
      rgba(0, 255, 255, 0.05) 2px,
      rgba(0, 255, 255, 0.05) 4px
    );
  border-color: #00ffff;
  box-shadow:
    0 6px 25px rgba(0, 255, 255, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    inset 0 -1px 0 rgba(0, 255, 255, 0.3);
  transform: translateY(-2px);
}

.history-item:hover::before {
  opacity: 1;
}

.history-item:hover::after {
  opacity: 1;
}

.history-item:active {
  transform: translateY(0) scale(0.98);
  transition: all 0.1s ease;
}

.history-item.active {
  background:
    linear-gradient(135deg, rgba(0, 255, 255, 0.3) 0%, rgba(255, 0, 255, 0.3) 100%),
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 10px,
      rgba(0, 255, 255, 0.05) 10px,
      rgba(0, 255, 255, 0.05) 11px
    );
  border-color: #00ffff;
  box-shadow:
    0 4px 20px rgba(0, 255, 255, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    inset 0 -1px 0 rgba(0, 255, 255, 0.4);
  animation: activePulse 2s ease-in-out infinite;
}

.history-item.active::before {
  opacity: 1;
}

.history-title {
  font-weight: 600;
  color: #00ffff;
  margin-bottom: 0.25rem;
  font-size: 0.875rem;
  text-shadow: 0 0 5px rgba(0, 255, 255, 0.5);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.history-preview {
  color: rgba(0, 255, 255, 0.7);
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 0 3px rgba(0, 255, 255, 0.3);
  font-family: 'Courier New', monospace;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .chat-header {
    padding: 1rem;
  }

  .messages-container {
    padding: 1rem;
  }

  .input-area {
    padding: 1rem;
  }

  .input-info {
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start;
  }

  .logo h1 {
    font-size: 1rem;
    letter-spacing: 1px;
  }

  .btn-text {
    display: none;
  }

  .icon-btn {
    padding: 0.5rem;
    min-width: 40px;
    justify-content: center;
  }

  .connection-status {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    gap: 0.5rem;
    min-height: 42px;
  }

  .status-indicator {
    width: 10px;
    height: 10px;
  }

  .reconnect-btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    margin-left: 0.5rem;
    min-height: 32px;
  }
}

/* Scrollbar Styling */
.messages-container::-webkit-scrollbar {
  width: 8px;
}

.messages-container::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, #00ffff 0%, #ff00ff 100%);
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
}

.messages-container::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, #00ffff 0%, #ff00ff 100%);
  box-shadow: 0 0 20px rgba(0, 255, 255, 0.8);
}

.chat-history::-webkit-scrollbar {
  width: 6px;
}

.chat-history::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 3px;
}

.chat-history::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, #00ffff 0%, #ff00ff 100%);
  border-radius: 3px;
  box-shadow: 0 0 8px rgba(0, 255, 255, 0.5);
}

.chat-history::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, #00ffff 0%, #ff00ff 100%);
  box-shadow: 0 0 15px rgba(0, 255, 255, 0.8);
}

/* Knowledge Search Carousel Section in Sidebar */
.knowledge-carousel-section {
  background: rgba(0, 20, 40, 0.6);
  border-radius: 8px;
  margin: 1rem 0;
  padding: 1rem;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 255, 255, 0.3);
  box-shadow:
    0 2px 10px rgba(0, 255, 255, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  position: relative;
  overflow: hidden;
}

.knowledge-carousel-section.bottom {
  margin: 0;
  border-top: 2px solid rgba(0, 255, 255, 0.3);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  height: 350px;
  flex-shrink: 0;
}

.carousel-container {
  height: 290px;
  overflow: hidden;
  position: relative;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(0, 255, 255, 0.1);
}

.knowledge-carousel-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image:
    linear-gradient(rgba(0, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 20px 20px;
  animation: gridMove 15s linear infinite;
  pointer-events: none;
  z-index: 1;
}

.carousel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(0, 255, 255, 0.2);
  position: relative;
  z-index: 2;
}

.carousel-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, #00ffff, transparent);
  animation: scanLine 3s linear infinite;
}

.carousel-header h3 {
  font-size: 0.75rem;
  font-weight: 600;
  color: #00ffff;
  margin: 0;
  text-shadow: 0 0 8px rgba(0, 255, 255, 0.8);
  text-transform: uppercase;
  letter-spacing: 1px;
  animation: neonGlow 2s ease-in-out infinite;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.625rem;
  color: #00ffff;
  text-shadow: 0 0 3px rgba(0, 255, 255, 0.5);
}

.pulse-dot {
  width: 4px;
  height: 4px;
  background: #00ffff;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(0, 255, 255, 0.8);
  animation: pulse 2s ease-in-out infinite;
}

.status-text {
  font-family: 'Courier New', monospace;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 0.875rem;
}

.carousel-container {
  height: 45px;
  overflow: hidden;
  position: relative;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(0, 255, 255, 0.1);
}

/* Right Sidebar - Monitoring Panel */
.workflow-sidebar {
  width: 280px;
  background:
    radial-gradient(ellipse at center, rgba(40, 0, 40, 0.95) 0%, rgba(0, 0, 0, 0.95) 100%),
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 2px,
      rgba(255, 0, 255, 0.03) 2px,
      rgba(255, 0, 255, 0.03) 4px
    ),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(255, 0, 255, 0.02) 2px,
      rgba(255, 0, 255, 0.02) 4px
    );
  border-left: none;
  border-right: 3px solid #ff00ff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100vh;
  backdrop-filter: blur(15px);
  box-shadow:
    -4px 0 40px rgba(255, 0, 255, 0.6),
    inset 1px 0 0 rgba(255, 255, 255, 0.1),
    inset -1px 0 0 rgba(255, 0, 255, 0.1);
  position: relative;
  z-index: 5;
  transform: none;
  clip-path: none;
  flex-shrink: 0;
  /* 监控面板网格效果 */
}

.workflow-sidebar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image:
    linear-gradient(rgba(255, 0, 255, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 0, 255, 0.1) 1px, transparent 1px);
  background-size: 20px 20px;
  animation: gridMove 15s linear infinite;
  pointer-events: none;
  z-index: 1;
}

.workflow-sidebar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(circle at 20% 80%, rgba(255, 0, 255, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255, 0, 255, 0.05) 0%, transparent 50%);
  animation: pulseGlow 4s ease-in-out infinite;
  pointer-events: none;
  z-index: 1;
}

.workflow-header {
  padding: 1rem;
  border-bottom: 2px solid #ff00ff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 60px;
  min-height: 60px;
  box-sizing: border-box;
  background:
    linear-gradient(135deg, rgba(40, 0, 40, 0.8) 0%, rgba(0, 0, 0, 0.8) 100%),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 10px,
      rgba(255, 0, 255, 0.05) 10px,
      rgba(255, 0, 255, 0.05) 11px
    );
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 2;
  flex-shrink: 0;
  /* 监控面板效果 */
  box-shadow:
    inset 0 2px 0 rgba(255, 0, 255, 0.3),
    inset 0 -2px 0 rgba(255, 0, 255, 0.1);
}

.workflow-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, #ff00ff, transparent);
  animation: scanLine 3s linear infinite;
}

.workflow-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: #00ffff;
  margin: 0;
  text-shadow: 0 0 10px rgba(0, 255, 255, 0.8);
  text-transform: uppercase;
  letter-spacing: 1px;
  animation: neonGlow 2s ease-in-out infinite;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.auto-scroll-btn {
  background: linear-gradient(135deg, rgba(0, 255, 255, 0.1) 0%, rgba(255, 0, 255, 0.1) 100%);
  border: 1px solid rgba(0, 255, 255, 0.3);
  border-radius: 8px;
  color: rgba(0, 255, 255, 0.8);
  padding: 0.375rem 0.5rem;
  font-size: 0.7rem;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(5px);
  box-shadow:
    0 2px 8px rgba(0, 255, 255, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.auto-scroll-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(0, 255, 255, 0.3), transparent);
  transition: left 0.6s ease;
}

.auto-scroll-btn:hover {
  background: linear-gradient(135deg, rgba(0, 255, 255, 0.2) 0%, rgba(255, 0, 255, 0.2) 100%);
  color: #ffffff;
  border-color: #00ffff;
  box-shadow:
    0 4px 12px rgba(0, 255, 255, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.auto-scroll-btn:hover::before {
  left: 100%;
}

.auto-scroll-btn.active {
  background: linear-gradient(135deg, rgba(0, 255, 255, 0.3) 0%, rgba(255, 0, 255, 0.3) 100%);
  border-color: #00ffff;
  color: #ffffff;
  box-shadow:
    0 4px 15px rgba(0, 255, 255, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  animation: activePulse 2s ease-in-out infinite;
}

.auto-scroll-btn .btn-icon {
  font-size: 0.8rem;
  filter: drop-shadow(0 0 3px rgba(0, 255, 255, 0.5));
}

.auto-scroll-btn .btn-text {
  font-size: 0.65rem;
  text-shadow: 0 0 3px rgba(0, 255, 255, 0.3);
}

.clear-btn {
  background: linear-gradient(135deg, rgba(255, 0, 255, 0.2) 0%, rgba(0, 255, 255, 0.2) 100%);
  border: 1px solid #ff00ff;
  border-radius: 8px;
  color: #ff00ff;
  padding: 0.375rem 0.5rem;
  font-size: 0.7rem;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(5px);
  box-shadow:
    0 2px 8px rgba(255, 0, 255, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.clear-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 0, 255, 0.3), transparent);
  transition: left 0.6s ease;
}

.clear-btn:hover {
  background: linear-gradient(135deg, rgba(255, 0, 255, 0.3) 0%, rgba(0, 255, 255, 0.3) 100%);
  color: #ffffff;
  border-color: #ff00ff;
  box-shadow:
    0 4px 12px rgba(255, 0, 255, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.clear-btn:hover::before {
  left: 100%;
}

.workflow-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1rem;
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 0;
  max-height: calc(100vh - 120px);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 0, 255, 0.6) rgba(0, 0, 0, 0.3);
}

.workflow-node {
  animation-delay: var(--delay, 0s);
  position: relative;
}

.node-connector {
  position: absolute;
  top: -20px;
  left: 50%;
  width: 2px;
  height: 20px;
  background: linear-gradient(180deg, rgba(255, 0, 255, 0.5), rgba(0, 255, 255, 0.5));
  z-index: 1;
}

.node-status-indicator {
  position: absolute;
  top: 50%;
  right: -8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transform: translateY(-50%);
  z-index: 3;
}

.workflow-node.running .node-status-indicator {
  background: #00ffff;
  box-shadow: 0 0 10px rgba(0, 255, 255, 0.8);
  animation: statusPulse 1.5s ease-in-out infinite;
}

.workflow-node.completed .node-status-indicator {
  background: #10b981;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.8);
  animation: statusCompletedPulse 2s ease-in-out infinite;
}

.workflow-node.error .node-status-indicator {
  background: #ef4444;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.8);
  animation: statusErrorPulse 1s ease-in-out infinite;
}

.workflow-node {
  display: flex;
  gap: 1rem;
  padding: 1.25rem;
  margin-bottom: 1rem;
  background:
    linear-gradient(135deg, rgba(40, 0, 40, 0.7) 0%, rgba(0, 0, 0, 0.7) 100%),
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 3px,
      rgba(255, 0, 255, 0.03) 3px,
      rgba(255, 0, 255, 0.03) 6px
    );
  border: 1px solid rgba(255, 0, 255, 0.4);
  border-radius: 12px;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  animation: slideInRight 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(15px);
  position: relative;
  overflow: hidden;
  cursor: pointer;
  flex-shrink: 0;
  min-height: 80px;
  /* 监控面板效果 */
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 0, 255, 0.3),
    inset 0 -1px 0 rgba(255, 0, 255, 0.2);
}

/* 添加数据流动效果 */
.workflow-node::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 0, 255, 0.1), transparent);
  animation: dataFlow 3s linear infinite;
  pointer-events: none;
  z-index: 1;
}

.workflow-node.running::after {
  animation-duration: 1.5s;
  background: linear-gradient(90deg, transparent, rgba(0, 255, 255, 0.2), transparent);
}

.workflow-node.completed::after {
  animation-duration: 4s;
  background: linear-gradient(90deg, transparent, rgba(16, 185, 129, 0.15), transparent);
}

.workflow-node.error::after {
  animation-duration: 1s;
  background: linear-gradient(90deg, transparent, rgba(239, 68, 68, 0.2), transparent);
}

.workflow-node::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255, 0, 255, 0.2) 0%, rgba(0, 255, 255, 0.2) 100%);
  border-radius: 12px;
  opacity: 0;
  transition: opacity 0.4s ease;
  z-index: -1;
}

.workflow-node::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(255, 0, 255, 0.8), transparent);
  opacity: 0;
  transition: opacity 0.4s ease;
}

/* 添加发光边框效果 */
.workflow-node .glow-border {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 12px;
  padding: 1px;
  background: linear-gradient(45deg, #ff00ff, #00ffff, #ff00ff);
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  transition: opacity 0.4s ease;
  z-index: -1;
}

.workflow-node:hover {
  background:
    linear-gradient(135deg, rgba(60, 0, 60, 0.9) 0%, rgba(0, 0, 0, 0.9) 100%),
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 3px,
      rgba(255, 0, 255, 0.08) 3px,
      rgba(255, 0, 255, 0.08) 6px
    );
  border-color: #ff00ff;
  box-shadow:
    0 12px 40px rgba(255, 0, 255, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    inset 0 -1px 0 rgba(255, 0, 255, 0.4);
  transform: translateY(-3px) scale(1.02);
}

.workflow-node:hover::before {
  opacity: 1;
}

.workflow-node:hover::after {
  opacity: 1;
}

.workflow-node:hover .glow-border {
  opacity: 0.7;
  animation: borderGlow 2s ease-in-out infinite;
}

.workflow-node:active {
  transform: translateY(-1px) scale(1.01);
  transition: all 0.2s ease;
}

.workflow-node.running {
  border-left: 4px solid #00ffff;
  background:
    linear-gradient(135deg, rgba(0, 255, 255, 0.4) 0%, rgba(40, 0, 40, 0.7) 100%),
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 8px,
      rgba(0, 255, 255, 0.08) 8px,
      rgba(0, 255, 255, 0.08) 16px
    );
  box-shadow:
    0 8px 32px rgba(0, 255, 255, 0.7),
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    inset 0 -1px 0 rgba(0, 255, 255, 0.5);
  animation: cyberPulse 2s ease-in-out infinite;
}

.workflow-node.running::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(0, 255, 255, 0.1), transparent);
  animation: dataFlow 2s linear infinite;
  z-index: -1;
}

.workflow-node.completed {
  border-left: 4px solid #10b981;
  background:
    linear-gradient(135deg, rgba(16, 185, 129, 0.4) 0%, rgba(40, 0, 40, 0.7) 100%),
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 8px,
      rgba(16, 185, 129, 0.08) 8px,
      rgba(16, 185, 129, 0.08) 16px
    );
  box-shadow:
    0 8px 32px rgba(16, 185, 129, 0.7),
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    inset 0 -1px 0 rgba(16, 185, 129, 0.5);
  animation: successGlow 3s ease-in-out infinite;
}

.workflow-node.completed::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at center, rgba(16, 185, 129, 0.2) 0%, transparent 70%);
  animation: successPulse 3s ease-in-out infinite;
  z-index: -1;
}

.workflow-node.error {
  border-left: 4px solid #ef4444;
  background:
    linear-gradient(135deg, rgba(239, 68, 68, 0.4) 0%, rgba(40, 0, 40, 0.7) 100%),
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 8px,
      rgba(239, 68, 68, 0.08) 8px,
      rgba(239, 68, 68, 0.08) 16px
    );
  box-shadow:
    0 8px 32px rgba(239, 68, 68, 0.7),
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    inset 0 -1px 0 rgba(239, 68, 68, 0.5);
  animation: errorPulse 1.5s ease-in-out infinite;
}

.workflow-node.error::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(45deg, transparent, rgba(239, 68, 68, 0.1), transparent);
  animation: errorShake 0.5s ease-in-out infinite;
  z-index: -1;
}

.node-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  position: relative;
  z-index: 2;
  transition: all 0.3s ease;
}

.workflow-node.running .node-icon {
  animation: iconPulse 1.5s ease-in-out infinite;
  filter: drop-shadow(0 0 8px rgba(0, 255, 255, 0.8));
}

.workflow-node.completed .node-icon {
  animation: iconBounce 0.6s ease-out;
  filter: drop-shadow(0 0 8px rgba(16, 185, 129, 0.8));
}

.workflow-node.error .node-icon {
  animation: iconShake 0.5s ease-in-out;
  filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.8));
}

@keyframes iconPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.2);
  }
}

@keyframes iconBounce {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.3);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes iconShake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

.node-content {
  flex: 1;
  min-width: 0;
}

.node-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
}

.node-actions {
  display: flex;
  gap: 0.25rem;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.workflow-node:hover .node-actions {
  opacity: 1;
}

.node-action-btn {
  background: linear-gradient(135deg, rgba(0, 0, 0, 0.6) 0%, rgba(40, 0, 40, 0.6) 100%);
  border: 1px solid rgba(255, 0, 255, 0.3);
  border-radius: 4px;
  color: rgba(255, 0, 255, 0.8);
  padding: 0.25rem;
  font-size: 0.7rem;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(5px);
}

.node-action-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 0, 255, 0.3), transparent);
  transition: left 0.4s ease;
}

.node-action-btn:hover {
  background: linear-gradient(135deg, rgba(255, 0, 255, 0.3) 0%, rgba(0, 255, 255, 0.3) 100%);
  color: #ffffff;
  border-color: #ff00ff;
  box-shadow: 0 2px 8px rgba(255, 0, 255, 0.4);
  transform: scale(1.1);
}

.node-action-btn:hover::before {
  left: 100%;
}

.node-action-btn.remove-btn:hover {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.3) 0%, rgba(220, 38, 127, 0.3) 100%);
  border-color: #ef4444;
  color: #ef4444;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
}

.node-action-btn.copy-btn:hover {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.3) 0%, rgba(6, 182, 212, 0.3) 100%);
  border-color: #10b981;
  color: #10b981;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.4);
}

.node-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(255, 0, 255, 0.1);
}

.node-progress {
  width: 100%;
  height: 3px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
  margin-top: 0.25rem;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #00ffff, #ff00ff);
  border-radius: 2px;
  position: relative;
  animation: progressFlow 2s ease-in-out infinite;
  box-shadow: 0 0 8px rgba(0, 255, 255, 0.5);
}

.progress-bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  animation: shimmer 1.5s infinite;
}

@keyframes progressFlow {
  0%,
  100% {
    width: 30%;
  }
  50% {
    width: 80%;
  }
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

.node-name {
  font-weight: 600;
  color: #00ffff;
  font-size: 0.875rem;
  margin-bottom: 0.25rem;
  text-shadow: 0 0 5px rgba(0, 255, 255, 0.5);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.node-description {
  color: rgba(0, 255, 255, 0.7);
  font-size: 0.75rem;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 0 3px rgba(0, 255, 255, 0.3);
  font-family: 'Courier New', monospace;
}

.output-preview {
  white-space: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  max-height: 1.2em;
  line-height: 1.2em;
  margin-bottom: 0.25rem;
}

.output-preview.expanded {
  max-height: none;
  white-space: pre-wrap;
  word-break: break-all;
}

.error-text {
  color: #ef4444;
  text-shadow: 0 0 3px rgba(239, 68, 68, 0.5);
}

.toggle-output-btn {
  background: linear-gradient(135deg, rgba(0, 255, 255, 0.1) 0%, rgba(255, 0, 255, 0.1) 100%);
  border: 1px solid rgba(0, 255, 255, 0.3);
  color: rgba(0, 255, 255, 0.8);
  padding: 0.25rem 0.5rem;
  font-size: 0.7rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 0.25rem;
  font-family: 'Courier New', monospace;
}

.toggle-output-btn:hover {
  background: linear-gradient(135deg, rgba(0, 255, 255, 0.2) 0%, rgba(255, 0, 255, 0.2) 100%);
  color: #ffffff;
  border-color: #00ffff;
  box-shadow: 0 2px 8px rgba(0, 255, 255, 0.3);
}

.toggle-output-btn.expanded {
  background: linear-gradient(135deg, rgba(255, 0, 255, 0.2) 0%, rgba(0, 255, 255, 0.2) 100%);
  border-color: #ff00ff;
}

.node-time {
  color: rgba(0, 255, 255, 0.6);
  font-size: 0.7rem;
  text-shadow: 0 0 3px rgba(0, 255, 255, 0.3);
  font-family: 'Courier New', monospace;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: rgba(0, 255, 255, 0.6);
  text-align: center;
  padding: 2rem;
  text-shadow: 0 0 5px rgba(0, 255, 255, 0.5);
  position: relative;
}

.empty-state::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100px;
  height: 100px;
  border: 2px solid rgba(0, 255, 255, 0.2);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: ripple 3s ease-in-out infinite;
}

.empty-state::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 60px;
  height: 60px;
  border: 1px solid rgba(255, 0, 255, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: ripple 3s ease-in-out infinite 1.5s;
}

@keyframes ripple {
  0% {
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(1.5);
    opacity: 0;
  }
}

.empty-icon {
  font-size: 2rem;
  margin-bottom: 1rem;
  animation: spin 2s linear infinite;
  filter: drop-shadow(0 0 10px #00ffff);
  text-shadow: 0 0 15px rgba(0, 255, 255, 0.8);
}

.empty-text {
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-family: 'Courier New', monospace;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes statusPulse {
  0%,
  100% {
    opacity: 0.6;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.2);
  }
}

@keyframes statusCompletedPulse {
  0%,
  100% {
    opacity: 0.8;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.1);
  }
}

@keyframes statusErrorPulse {
  0%,
  100% {
    opacity: 0.7;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.15);
  }
}

@keyframes successGlow {
  0%,
  100% {
    box-shadow:
      0 8px 32px rgba(16, 185, 129, 0.4),
      inset 0 1px 0 rgba(255, 255, 255, 0.2),
      inset 0 -1px 0 rgba(16, 185, 129, 0.3);
  }
  50% {
    box-shadow:
      0 12px 40px rgba(16, 185, 129, 0.6),
      inset 0 1px 0 rgba(255, 255, 255, 0.3),
      inset 0 -1px 0 rgba(16, 185, 129, 0.5);
  }
}

@keyframes successPulse {
  0%,
  100% {
    opacity: 0.3;
  }
  50% {
    opacity: 0.6;
  }
}

@keyframes errorPulse {
  0%,
  100% {
    box-shadow:
      0 8px 32px rgba(239, 68, 68, 0.4),
      inset 0 1px 0 rgba(255, 255, 255, 0.2),
      inset 0 -1px 0 rgba(239, 68, 68, 0.3);
  }
  50% {
    box-shadow:
      0 12px 40px rgba(239, 68, 68, 0.6),
      inset 0 1px 0 rgba(255, 255, 255, 0.3),
      inset 0 -1px 0 rgba(239, 68, 68, 0.5);
  }
}

@keyframes errorShake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-2px);
  }
  75% {
    transform: translateX(2px);
  }
}

@keyframes borderGlow {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
  }
}

@keyframes dataFlow {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

@keyframes gridMove {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 20px 20px;
  }
}

@keyframes pulseGlow {
  0%,
  100% {
    opacity: 0.3;
  }
  50% {
    opacity: 0.6;
  }
}

@keyframes scanLine {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes glitch {
  0%,
  100% {
    transform: translate(0);
  }
  20% {
    transform: translate(-2px, 2px);
  }
  40% {
    transform: translate(-2px, -2px);
  }
  60% {
    transform: translate(2px, 2px);
  }
  80% {
    transform: translate(2px, -2px);
  }
}

@keyframes hologram {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.8;
  }
}

@keyframes cyberPulse {
  0%,
  100% {
    box-shadow:
      0 0 20px rgba(0, 255, 255, 0.4),
      0 0 40px rgba(0, 255, 255, 0.2),
      inset 0 0 20px rgba(0, 255, 255, 0.1);
  }
  50% {
    box-shadow:
      0 0 30px rgba(0, 255, 255, 0.6),
      0 0 60px rgba(0, 255, 255, 0.3),
      inset 0 0 30px rgba(0, 255, 255, 0.2);
  }
}

/* Cyberpunk text effects */
.cyber-text {
  background: linear-gradient(45deg, #00ffff, #ff00ff, #00ffff);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 3s ease infinite;
}

/* Hologram effect */
.hologram {
  position: relative;
  overflow: hidden;
}

.hologram::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(45deg, transparent, rgba(0, 255, 255, 0.1), transparent);
  animation: hologram 2s linear infinite;
}

/* Glitch effect */
.glitch {
  position: relative;
  animation: glitch 3s infinite;
}

.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.glitch::before {
  animation: glitch-1 0.8s infinite;
  color: #00ffff;
  z-index: -1;
  clip-path: polygon(0 0, 100% 0, 100% 45%, 0 45%);
}

.glitch::after {
  animation: glitch-2 0.8s infinite;
  color: #ff00ff;
  z-index: -2;
  clip-path: polygon(0 55%, 100% 55%, 100% 100%, 0 100%);
}

/* Random glitch effect */
.random-glitch {
  animation: randomGlitch 4s infinite;
}

@keyframes randomGlitch {
  0%,
  90%,
  100% {
    transform: translate(0) skew(0deg);
    filter: hue-rotate(0deg);
  }
  91% {
    transform: translate(-2px, 2px) skew(1deg);
    filter: hue-rotate(90deg);
  }
  92% {
    transform: translate(2px, -2px) skew(-1deg);
    filter: hue-rotate(180deg);
  }
  93% {
    transform: translate(-1px, 1px) skew(0.5deg);
    filter: hue-rotate(270deg);
  }
  94% {
    transform: translate(1px, -1px) skew(-0.5deg);
    filter: hue-rotate(360deg);
  }
}

/* Circuit board texture */
.circuit-texture {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image:
    radial-gradient(circle at 25% 25%, rgba(0, 255, 255, 0.1) 1px, transparent 1px),
    radial-gradient(circle at 75% 75%, rgba(255, 0, 255, 0.1) 1px, transparent 1px),
    linear-gradient(0deg, transparent 49%, rgba(0, 255, 255, 0.05) 50%, transparent 51%),
    linear-gradient(90deg, transparent 49%, rgba(255, 0, 255, 0.05) 50%, transparent 51%);
  background-size:
    50px 50px,
    30px 30px,
    20px 20px,
    15px 15px;
  background-position:
    0 0,
    25px 25px,
    0 0,
    0 0;
  animation: circuitMove 20s linear infinite;
  pointer-events: none;
  z-index: 1;
  opacity: 0.6;
}

@keyframes circuitMove {
  0% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(10px, -15px);
  }
  50% {
    transform: translate(-15px, 10px);
  }
  75% {
    transform: translate(5px, 20px);
  }
  100% {
    transform: translate(0, 0);
  }
}

@keyframes glitch-1 {
  0%,
  100% {
    clip-path: inset(0 0 0 0);
    transform: translate(0);
  }
  20% {
    clip-path: inset(20% 0 30% 0);
    transform: translate(-2px, 2px);
  }
  40% {
    clip-path: inset(50% 0 20% 0);
    transform: translate(2px, -2px);
  }
  60% {
    clip-path: inset(10% 0 60% 0);
    transform: translate(-2px, 2px);
  }
  80% {
    clip-path: inset(80% 0 5% 0);
    transform: translate(2px, -2px);
  }
}

@keyframes glitch-2 {
  0%,
  100% {
    clip-path: inset(0 0 0 0);
    transform: translate(0);
  }
  20% {
    clip-path: inset(60% 0 20% 0);
    transform: translate(2px, -2px);
  }
  40% {
    clip-path: inset(20% 0 50% 0);
    transform: translate(-2px, 2px);
  }
  60% {
    clip-path: inset(30% 0 40% 0);
    transform: translate(2px, -2px);
  }
  80% {
    clip-path: inset(5% 0 80% 0);
    transform: translate(-2px, 2px);
  }
}

/* Dashboard and Data Display Effects */
.dashboard-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 1rem;
  background:
    linear-gradient(135deg, rgba(40, 0, 40, 0.8) 0%, rgba(0, 0, 0, 0.8) 100%),
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 10px,
      rgba(255, 0, 255, 0.03) 10px,
      rgba(255, 0, 255, 0.03) 11px
    );
  border: 1px solid rgba(255, 0, 255, 0.3);
  border-radius: 8px;
  backdrop-filter: blur(10px);
  position: relative;
  /* 监控面板效果 */
  box-shadow:
    inset 0 1px 0 rgba(255, 0, 255, 0.2),
    inset 0 -1px 0 rgba(255, 0, 255, 0.1),
    0 4px 15px rgba(0, 0, 0, 0.3);
}

.dashboard-metrics::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255, 0, 255, 0.1) 0%, rgba(0, 255, 255, 0.1) 100%);
  border-radius: 8px;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: -1;
}

.dashboard-metrics:hover::before {
  opacity: 1;
}

.metric-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  position: relative;
}

.metric-label {
  font-size: 0.7rem;
  color: rgba(0, 255, 255, 0.7);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 0.25rem;
  text-shadow: 0 0 3px rgba(0, 255, 255, 0.5);
  font-family: 'Courier New', monospace;
}

.metric-value {
  font-size: 1.25rem;
  font-weight: 600;
  color: #00ffff;
  text-shadow: 0 0 10px rgba(0, 255, 255, 0.8);
  font-family: 'Courier New', monospace;
}

.metric-unit {
  font-size: 0.75rem;
  color: rgba(0, 255, 255, 0.6);
  margin-left: 0.25rem;
  text-shadow: 0 0 3px rgba(0, 255, 255, 0.3);
}

.metric-indicator {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

.metric-indicator.online {
  background: #10b981;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.8);
}

.metric-indicator.warning {
  background: #f59e0b;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.8);
}

.metric-indicator.error {
  background: #ef4444;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.8);
}

/* Progress bars for workflow nodes */
.workflow-progress {
  width: 100%;
  height: 4px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 2px;
  margin-top: 0.5rem;
  overflow: hidden;
  position: relative;
}

.workflow-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #00ffff, #ff00ff);
  border-radius: 2px;
  transition: width 0.3s ease;
  position: relative;
  box-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
}

.workflow-progress-bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

/* System status indicators */
.status-panel {
  background:
    linear-gradient(135deg, rgba(40, 0, 40, 0.6) 0%, rgba(0, 0, 0, 0.6) 100%),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 2px,
      rgba(255, 0, 255, 0.02) 2px,
      rgba(255, 0, 255, 0.02) 4px
    );
  border: 1px solid rgba(255, 0, 255, 0.3);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
  backdrop-filter: blur(10px);
  position: relative;
  /* 监控面板效果 */
  box-shadow:
    inset 0 1px 0 rgba(255, 0, 255, 0.2),
    inset 0 -1px 0 rgba(255, 0, 255, 0.1),
    0 4px 15px rgba(0, 0, 0, 0.3);
}

.status-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255, 0, 255, 0.1) 0%, rgba(0, 255, 255, 0.1) 100%);
  border-radius: 8px;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: -1;
}

.status-panel:hover::before {
  opacity: 1;
}

.status-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(255, 0, 255, 0.2);
}

.status-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #00ffff;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-shadow: 0 0 5px rgba(0, 255, 255, 0.5);
}

.status-badge {
  font-size: 0.7rem;
  padding: 0.25rem 0.5rem;
  border-radius: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-badge.online {
  background: rgba(16, 185, 129, 0.2);
  color: #10b981;
  border: 1px solid #10b981;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.3);
}

.status-badge.warning {
  background: rgba(245, 158, 11, 0.2);
  color: #f59e0b;
  border: 1px solid #f59e0b;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.3);
}

.status-badge.error {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  border: 1px solid #ef4444;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.3);
}

.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.status-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0;
  border-bottom: 1px solid rgba(255, 0, 255, 0.1);
}

.status-item:last-child {
  border-bottom: none;
}

.status-label {
  font-size: 0.7rem;
  color: rgba(0, 255, 255, 0.7);
  text-shadow: 0 0 3px rgba(0, 255, 255, 0.3);
  font-family: 'Courier New', monospace;
}

.status-value {
  font-size: 0.7rem;
  color: #00ffff;
  font-weight: 600;
  text-shadow: 0 0 3px rgba(0, 255, 255, 0.5);
  font-family: 'Courier New', monospace;
}

/* Real-time data animation */
.data-stream {
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(0, 255, 255, 0.1), transparent);
  animation: dataFlow 3s linear infinite;
  pointer-events: none;
}

@keyframes dataFlow {
  0% {
    left: -100%;
  }
  100% {
    left: 100%;
  }
}

/* Workflow Sidebar Scrollbar */
.workflow-container::-webkit-scrollbar {
  width: 8px;
}

.workflow-container::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 4px;
  border: 1px solid rgba(255, 0, 255, 0.2);
}

.workflow-container::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, #ff00ff 0%, #00ffff 100%);
  border-radius: 4px;
  border: 1px solid rgba(255, 0, 255, 0.3);
  box-shadow: 
    0 0 10px rgba(255, 0, 255, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.workflow-container::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, #ff00ff 0%, #00ffff 100%);
  box-shadow: 
    0 0 20px rgba(255, 0, 255, 0.8),
    0 0 30px rgba(0, 255, 255, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 0, 255, 0.6);
}

/* Responsive */
@media (max-width: 1024px) {
  .workflow-sidebar {
    width: 220px;
  }

  .workflow-header h3 {
    font-size: 0.875rem;
  }

  .auto-scroll-btn .btn-text,
  .clear-btn {
    font-size: 0.65rem;
    padding: 0.25rem 0.375rem;
  }

  .workflow-node {
    padding: 1rem;
    margin-bottom: 0.75rem;
    min-height: 70px;
  }

  .workflow-container {
    padding: 1rem 0.75rem;
    gap: 0.375rem;
  }

  .node-name {
    font-size: 0.8rem;
  }

  .node-description {
    font-size: 0.7rem;
  }
}

@media (max-width: 768px) {
  .workflow-sidebar {
    display: none;
  }

  .main-content {
    max-width: none;
  }
}

/* Mobile responsive */
@media (max-width: 480px) {
  .chat-header {
    padding: 0.75rem;
  }

  .logo h1 {
    font-size: 0.875rem;
    letter-spacing: 0.5px;
  }

  .logo-icon {
    font-size: 1.25rem;
  }

  .messages-container {
    padding: 0.75rem;
  }

  .message.user .message-text,
  .message.assistant .message-text {
    font-size: 0.875rem;
    padding: 0.5rem;
  }

  .input-area {
    padding: 0.75rem;
  }

  .message-input {
    font-size: 0.875rem;
    padding: 0.5rem;
  }

  .send-btn {
    width: 40px;
    height: 40px;
    font-size: 1rem;
  }
}

/* High contrast mode for accessibility */
@media (prefers-contrast: high) {
  .chat-container {
    border-width: 3px;
  }

  .message.user .message-text,
  .message.assistant .message-text {
    border-width: 2px;
  }

  .icon-btn {
    border-width: 2px;
  }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .chat-container::before,
  .chat-container::after,
  .messages-container::before,
  .chat-history::before,
  .workflow-container::before,
  .modal-body::before {
    animation: none;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .chat-container {
    background: linear-gradient(135deg, #000000 0%, #1a1a2e 50%, #16213e 100%);
  }
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(0, 0, 0, 0.9) 0%, rgba(26, 26, 46, 0.9) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(10px);
  border: 2px solid #00ffff;
  box-shadow:
    inset 0 0 50px rgba(0, 255, 255, 0.2),
    0 0 100px rgba(0, 255, 255, 0.4);
}

/* Animated background particles */
.modal-overlay::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255, 119, 198, 0.3) 0%, transparent 50%),
    radial-gradient(circle at 40% 40%, rgba(120, 219, 255, 0.2) 0%, transparent 50%);
  animation: particleFloat 20s ease-in-out infinite;
  pointer-events: none;
  z-index: 1;
}

.modal-content {
  background: linear-gradient(135deg, rgba(0, 0, 0, 0.9) 0%, rgba(26, 26, 46, 0.9) 100%);
  border-radius: 16px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow: hidden;
  box-shadow:
    0 20px 25px -5px rgba(0, 255, 255, 0.3),
    0 10px 10px -5px rgba(255, 0, 255, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  border: 2px solid #00ffff;
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 2;
}

/* Grid overlay */
.modal-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image:
    linear-gradient(rgba(0, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 20px 20px;
  animation: gridMove 10s linear infinite;
  pointer-events: none;
  z-index: 1;
}

.modal-header {
  padding: 1.5rem;
  border-bottom: 2px solid #00ffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(5px);
  position: relative;
  z-index: 3;
}

/* Scanning line effect */
.modal-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  right: -100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #00ffff, transparent);
  animation: scanLine 3s linear infinite;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #00ffff;
  text-shadow:
    0 0 10px #00ffff,
    0 0 20px #00ffff,
    0 0 30px #00ffff;
  animation: neonGlow 2s ease-in-out infinite;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.close-btn {
  background: linear-gradient(135deg, rgba(255, 0, 255, 0.2) 0%, rgba(0, 255, 255, 0.2) 100%);
  border: 1px solid #ff00ff;
  font-size: 1.5rem;
  color: #ff00ff;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  box-shadow:
    0 4px 15px rgba(255, 0, 255, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.close-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  transition: left 0.6s ease;
}

.close-btn:hover {
  background: linear-gradient(135deg, rgba(255, 0, 255, 0.3) 0%, rgba(0, 255, 255, 0.3) 100%);
  color: #ffffff;
  box-shadow:
    0 6px 20px rgba(255, 0, 255, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

.close-btn:hover::before {
  left: 100%;
}

.modal-body {
  padding: 0;
  overflow-y: auto;
  max-height: calc(80vh - 80px);
  background: rgba(0, 0, 0, 0.2);
  position: relative;
  z-index: 3;
}

/* Data stream effect */
.modal-body::before {
  content: '';
  position: absolute;
  top: -100%;
  left: 0;
  right: 0;
  height: 100%;
  background: linear-gradient(180deg, transparent, rgba(0, 255, 255, 0.05), transparent);
  animation: dataStream 8s linear infinite;
  pointer-events: none;
}
</style>